Ext.define('AM.view.AllEmpfinaceView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.allempfinaceView',
		store : 'AllEmpFinaceStore',
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'), 
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"  //"SINGLE"/"SIMPLE"/"MULTI"
	       
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [
//    		{
//        xtype: 'pagingtoolbar',
//        dock: 'bottom',
//        store : 'EmpFinaceStore',
//        displayInfo: true
//        },
        	{
	     dock: 'top',
	     xtype: 'toolbar',
	     items: [ {
	        xtype:'datefield',
	        format:'Y-m', 
	        labelWidth:30,
	        fieldLabel: '日期',
	        id:'allempfinace_date',
	        width : 200
	      },
//	      ,'-',{
//		     xtype : "combobox",
//		     allowBlank:false,
//		     emptyText:'请选择科室',
//			 selectOnFocus:true,
//			 forceSelection: true,
//			 queryMode: 'local',
//			 labelWidth:30,
//			 fieldLabel: '科室',
//			 name: 'searchdepartment',
//			 store :"DepartmentStore",
//			 displayField: 'name',
//			 valueField: 'id',
//			 id:'empfinace_dept',
//	         width : 200,
//	         listeners:{   
//					select:function(combo, record,index){
//								 try{ 
//								 var rewar;
//								 var date=Ext.getCmp('empfinace_date').getValue();
//								 var date1=Ext.util.Format.date(date, 'Y-m');
//								 Ext.Ajax.request({
//										url : 'departmentFinaceAction_deptfinace',
//									    async : false,
//										success : function(response, options) {
//											var re =Ext.JSON.decode(response.responseText);
//											rewar=re.rewad;
//										},
//										failure : function() {
//											Ext.MessageBox.alert("提示", "科室本月无测算奖金！");
//										},
//										params : {
//											dept:this.value,
//											searchdate:date1
//										}
//									});	
//									 var parent=Ext.getCmp('empfinace_reward');
//									 parent.reset();
//									 parent.setValue(rewar);													 
//								 }
//								 catch(ex){
//									 Ext.MessageBox.alert("错误","数据加载失败。");
//								 }
//							}
//					}
//	      },'-', {
//	          xtype:'numberfield', 
//			  minValue: 0,
//			  fieldLabel: '科室奖金',
//			  labelWidth:60,
//			  readOnly:true,
//			  labelAlign :"right",
//		      name: 'totalReward',
//		      nanText:"输入必须为数字",
//		      id:'empfinace_reward',
//	          width :200
//	      },'-',
	      {
	            xtype: 'button',
	            text: '计算奖金',
	            icon : 'Ext/restful/images/find.png',
	            margin: '0 0 0 5',
	            handler: function () {
	            	
//	                 var department= Ext.getCmp('empfinace_dept').getValue(); //获取文本框值
//	                 var  reward = Ext.getCmp('empfinace_reward').getValue();
	                 var searchdate1 = Ext.getCmp('allempfinace_date').getValue();
	                 var grid=this.ownerCt.ownerCt;
	                 if(searchdate1===null){
	                 	alert("请选择月份");
	                 }else{
	                 	Ext.MessageBox.show({
				                            title: '计算',
				                            msg: '正在计算中...请等待结果',
				                            progressText: '',
//				                            width: 300,
//				                            increment: 1,
//                                            minValue: 0,
//                                            maxValue: 7200,
//				                            progress: true,
//				                            closable: false,
				                            animateTarget: 'mb'
					                        });
					                        
					//       >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.    
					          Ext.Ajax.request({
										url : 'performance_HSCountEmpPerformance',
										timeout: 100000000,
										success : function(response,opts) {
											var res=Ext.decode(response.responseText) ; 
											 grid.getStore().load({ params:{searchdate1:Ext.util.Format.date(searchdate1, 'Y-m')}});
											 if(res.success==false){
											 	Ext.MessageBox.hide();
											 	var a=res.msg;
                                                if(a.length>3){
                                                 alert("报错原因：["+a+"]"+"数据不完整，请通知相关负责人");
                                                 
                                               }
											   }else{
											   	 Ext.MessageBox.hide();
											   }
//											 	grid.getStore().on('beforeload', function (store, options) {
//			                                    var new_params = {searchdate:Ext.util.Format.date(searchdate1, 'Y-m')};
//			                                    Ext.apply(store.proxy.extraParams, new_params);
//			                                    });
//			                                    grid.getStore().reload();
											},
										failure : function() {
														Ext.MessageBox.alert("提示", "计算失败，请检查是否进行本月人员考评！");
									    	},
									   params:{searchdate1:Ext.util.Format.date(searchdate1, 'Y-m')
									   		}
									});	            
					    }                    
	                
	                
	                 
	                 
	                }
	        },{
	            xtype: 'button',
	            text: '查询奖金',
	            icon : 'Ext/restful/images/find.png',
	            margin: '0 0 0 5',
	            handler: function () {alert('hello!')}
	        },{
	        	xtype: 'button',
	            text: '导出奖金',
	            icon : 'Ext/restful/images/down2.png',
	            margin: '0 0 0 15',
	            handler: function () {
//	                 var department= Ext.getCmp('empfinace_date').getValue(); //获取文本框值
	                 var searchdate = Ext.util.Format.date(Ext.getCmp('allempfinace_date').getValue(), 'Y-m');
	                 window.location.href ="exportEmpfinaceAction?searchdate="+searchdate+" ";
	       		 }
	       },{
	        	xtype: 'button',
	            text: '重置科室计算',
	            icon : 'Ext/restful/images/dept.png',
	            margin: '0 0 0 50',
	            handler: shezhidept
	       }
	       ]
        }],
		columns: [
			        { text: 'ID', dataIndex: 'id',width:0,align:'center'},
			        {text: '序号',  xtype: 'rownumberer',width:50,align:'center',tdCls:'background-color: #8EE5EE;'},
			        { text: '姓名', dataIndex: 'employee', width:70,align:'center'},
			        { text: '应发总奖金', dataIndex: 'reward', width:100,align:'center',xtype:'numbercolumn', format:'0.00'},
			   		{ text: '科室', dataIndex: 'department', width:100,align:'center'},
			        { text: '日期', dataIndex: 'date',width:100,align:'center'}
			        
			     ]

})

function  shezhidept (){
	
	//alert('模块构建中！');
	var checkStore = Ext.create('Ext.data.Store', {
    fields:[
		  			{ name: 'id', type:'int'},
					{ name: 'deptname', type: 'string'},
				    { name: 'monthdate', type: 'string'},
				    { name: 'flag', type: 'int' }
				   
				 ],
     proxy:{
	     	type: 'ajax',
		 	url: 'department_ListhscheckDepartment.action',
		 	reader:{
				 	type:'json',
				 	root:'departments'
			 },
			 actionMethods: {  
            	read: 'POST'  
        	} 
	     },
	     autoLoad:false
         
    	
 });
var gridcheckdept=Ext.create('Ext.grid.Panel', {
	
    title: '',
    id:'gridcheckdept',
    autoScroll : true,
    selModel : Ext.create('Ext.selection.CheckboxModel'), 
    store: checkStore,
    dockedItems: [

        	{
	     dock: 'top',
	     xtype: 'toolbar',
	     items: ['-',' 日期: ', {
	        xtype:'datefield',
	        format:'Y-m',
	        editable:false,
	        id: 'hscheckdate',            
	        width : 150
	      }, {
	        	xtype: 'button',
	            text: '查询',
	            icon : 'Ext/restful/images/043.gif',
	            margin: '0 0 0 15',
	            handler: function () {
	            	 var grid=Ext.getCmp('gridcheckdept');
	            	 var searchdate1 = Ext.getCmp('hscheckdate').getValue();
	                 if(searchdate1===null){
	                 	alert("请选择月份");
	                 }else{
	                  grid.getStore().load({params:{searchdate1:Ext.util.Format.date(searchdate1, 'Y-m')}});
	                 }
	            }
	       }
	      
	       
	       
	       ]
        }],
    columns: [
        { text: 'ID',  dataIndex: 'id',   width: 0 },
        {text: '序号',  xtype: 'rownumberer',width:50,align:'center',tdCls:'background-color: #8EE5EE;'},
        { text: '科室名称',  dataIndex: 'deptname', align:'center', width: 100},
        { text: '状态', dataIndex: 'flag',align:'center', width: 100,renderer: function(value){
           if (value === 0) {
										 return  '<SPAN style="COLOR: red">未计算</SPAN>';
								 }if (value === 1) {
										 return '已完成';
								 }
          
        } },
        
        //{ text: '操作',  dataIndex: 'button' ,width:130,align:'center'}
        { text: '操作', dataIndex: 'id',width:100,align:'center',renderer : function(data, cell, record, rowIndex,columnIndex){
			        	    var resultStr = "<div class='controlBtn'>" +     
                            "<a href='javascript:void("+record.get('id')+");  'class='alarm_detail 'onclick='showbutton("+record.get('id')+")'>改变状态</a>&nbsp;&nbsp;&nbsp;&nbsp;" +     
                            "</div>";     
         					 return resultStr;  
	    }
         	    	}
    ],
    height: 500,
    width:600
   // renderTo: Ext.getBody()
});

	
	
var win= new Ext.Window({
				        title : "计算科室设置",
					    width : 500,
					    height : 500,
						closable : true,
					    draggable : true,
					    frame:true,
					    modal: true,
					    minimizable:true,
					    maximizable:true, 
					 	layout: 'fit', 
					    plain : true,
					    items: [gridcheckdept]
					      
						}).show();

}	
function showbutton(id){
	 Ext.Ajax.request({
                url:'department_trunhscheckDepartment.action',
                success: function (response) {
                   // var curnum = response.responseText;
                var res=Ext.decode(response.responseText) ;
                 if(res.success==true){
                  alert("ok!")
                  var searchdate1 = Ext.getCmp('hscheckdate').getValue();
               	 var grid=Ext.getCmp('gridcheckdept');
	              grid.getStore().reload({params:{searchdate1:Ext.util.Format.date(searchdate1, 'Y-m')}});
	                 
                 }
//                var curnum=res.worktime;
//                alert(curnum+"curnumcurnum");
                   
                },
                  params : {
							checkdeptid:id
						   }
            });
}